package com.example.algorithm.aPrimarySort;

/**
 * @author: dangwen
 * @createDate: 2021/7/1
 */
public class ChooseSort {
    public static void sort(int[] arr){

        int temp;
        for (int i = 0; i < arr.length; i++) {
            int min = arr[i];
            int index = i;
            for (int j = i+1; j < arr.length; j++) {
                if(arr[j] < min){
                    min = arr[j];
                    index = j;
                }
            }
            temp = arr[i];
            arr[i] = min;
            arr[index] = temp;
        }
    }

    public static void main(String[] args) {
        int arr[] = {8, 5, 3, 2, 4};
        sort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
